/*
 * @Author: 一路向阳 tt_sunzhenfeng@163.com
 * @Date: 2024-02-06 18:19:35
 * @LastEditors: 一路向阳 tt_sunzhenfeng@163.com
 * @LastEditTime: 2024-02-28 16:50:14
 * @FilePath: \utils_react_manager\app\src\hooks\useCaptcha.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { useRef, useCallback, useEffect } from "react";
import { message } from 'antd';
import {getCaptchaCode} from '@/api/login';

const useCaptcha = () => {
  const captchaRef = useRef<any>();

  const getCaptcha = useCallback(async () => {
    try {
      const { uuid, data } = await getCaptchaCode();
      // 本地保存uuid 登录时校验
      localStorage.setItem('uuid', uuid);
      captchaRef.current.innerHTML = data;
    }
    catch (error: any) {
      message.error(error);
    }
  }, []);

  useEffect(() => {
    getCaptcha();
  }, []);


  return {
    captchaRef,
    getCaptcha
  };
};


export default useCaptcha;
